package com.lz.rocketmq.consumer.project.listener.exception;

import com.lz.rocketmq.consumer.common.utils.DateUtils;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 异常重试 自定义重试次数 maxReconsumeTimes
 *
 * @author Administrator
 */
@Service
@RocketMQMessageListener(consumerGroup = "e2",
        topic = "exp-topic",
        messageModel = MessageModel.CLUSTERING,
        maxReconsumeTimes = 3 // 最大重试次数，默认为16
)
public class ConsumerExpE2Service implements RocketMQListener<String> {
    private static final Logger logger = LoggerFactory.getLogger(ConsumerExpE2Service.class);

    public static int t = 1;

    @Override
    public void onMessage(String message) {
        try {
            //测试时打开
            //double a = 1 / 0;
            System.out.println(String.format("日期: %s Service:%s group: %s topic: %s messageModel:%s msg:%s", DateUtils.getCurr_YYYY_MM_DD_HH_MM_SS_SSS(), "expE2", "e2", "exp-topic", "广播", message));

        } catch (Exception e) {
            logger.error("expE2 异常重试：" + (t++));
            throw new RuntimeException(e);
        }
    }

}